<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>详情页</title>
    <link rel="stylesheet" href="../static/css/me.css" th:href="@{/css/me.css}">
    <link rel="stylesheet" href="https://unpkg.com/semantic-ui@2.4.2/dist/semantic.min.css">
    <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
</head>
<body>
<!--导航-->
<nav class="ui inverted attached segment m-padded-tb-mini">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">Social Rescue Forces Sys.</h2>
            <a href="index.html" th:href="@{/}" class="m-item item m-mobile-hide"><i class="home icon"></i>首页</a>
            <a href="repo.html" th:href="@{/repo}" class="m-item item m-mobile-hide"><i class="book icon"></i>仓库</a>
            <a href="upload.html" th:href="@{/upload}" class="m-item item m-mobile-hide"><i class="share alternate square icon"></i>信息上报</a>
            <a href="news.html" th:href="@{/news}" class="m-item item m-mobile-hide"><i class="newspaper outline icon"></i>News</a>
            <div class="right m-item item m-mobile-hide">
                <form name="search" action="#" method="post" th:action="@{/search}" target="_blank">
                    <div class="ui icon inverted transparent input">
                        <input type="text" name="query" placeholder="输入关键字进行查找..." th:value="${query}">
                        <i onclick="document.forms['search'].submit()" class="search icon link"></i>
                    </div>
                </form>
            </div>
            <a th:href="@{/admin}" class="m-item item m-mobile-hide"><i class="user icon"></i></a>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!--中间内容-->
<div class="m-container-small m-padded-tb-big animated fadeIn">
    <div class="ui container">
        <div class="ui top attached segment">
            <div class="ui horizontal link list">
                <div class="item">
                    <i class="calendar icon"></i>
                    <span th:text="${#dates.format(force.updateTime,'yyyy-MM-dd HH:mm')}">2021-7-20</span>
                </div>
                <div class="item">
                    <i class="eye icon"></i>
                    <span th:text="${force.views}">123</span>
                </div>
            </div>
        </div>
        <div class="ui attached segment">
            <!--图片区域-->
            <img src="https://picsum.photos/id/1005/800/400" th:src="@{${force.firstPicture}}" alt="" class="ui centered small rounded image">
        </div>
        <div class="ui attached padded segment">
            <!--            内容-->
            <h2 class="ui center aligned header" th:text="${force.title}">关于排版</h2>
            <div class="ui divider"></div>
            <div class="ui center aligned container">
                <div class="ui divided stackable grid">
                    <div class="five wide column">
                        <h4>Email : </h4><span th:text="${force.email}"></span>
                    </div>
                    <div class="six wide column">
                        <h4>Tel : </h4><span th:text="${force.tel}"></span>
                    </div>
                    <div class="five wide column">
                        <h4>Address : </h4><span th:text="${force.addr}"></span>
                    </div>
                </div>
            </div>
            <div class="ui divider"></div>
            <div id="content" class="m-padded-lr-responsive m-padded-tb-large" th:text="${force.content}">
            </div>
                <form id="email-form" action="#" th:Object="${email}" th:action="@{/sendEmail/{id}(id=${force.id})}" method="post" th:methon="post" class="ui form">
                    <div class="ui container">
                        <div class="required field">
                            <input type="text" name="Econtent" placeholder="邮件内容"  th:value="*{Econtent}">
                            <input type="hidden" name="Ereceiver" th:value="*{Ereceiver}">
                        </div>
                        <div class="ui right aligned container">
                            <button type="button" id="send-btn" class="ui teal button m-mobile-wide">发送</button>
                        </div>
                        <div class="ui negative message" th:unless="${#strings.isEmpty(msg)}">
                            <i class="close icon"></i>
                            <p th:text="${msg}"></p>
                        </div>
                    </div>
                </form>
            <div class="ui divider"></div>
            <div class="m-padded-lr">
                <div class="ui basic teal left pointing label" th:text="${force.type.name}">火灾救援</div>
                <div class="ui basic teal left pointing label" th:text="${force.province.name}">山东</div>
            </div>

        </div>

        <div class="ui bottom attached segment"  th:if="${force.commentable}">
            <!--留言区域列表-->
            <div id="comment-container" class="ui teal segment">
                <div th:fragment="commentList">
                    <div class="ui threaded comments" style="max-width: 100%">
                        <h3 class="ui dividing header">评论</h3>
                        <div class="comment" th:each="comment : ${comments}">
                            <a class="avatar">
                                <img src="https://picsum.photos/id/1009/100/100" th:src="@{${comment.avatar}}">
                            </a>
                            <div class="content">
                                <a class="author" >
                                    <span th:text="${comment.nickname}">Matt</span>
                                </a>
                                <div class="metadata">
                                    <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                </div>
                                <div class="text" th:text="${comment.content}">
                                    How artistic!
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="comment-form" class="ui form">
                <input type="hidden" name="force.id" th:value="${force.id}">
                <div class="field">
                    <textarea name="content" placeholder="请输入评论内容..."></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-mini">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" placeholder="姓名">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-mini">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" name="email" placeholder="邮箱">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-mini">
                        <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide"><i class="edit icon"></i>发布</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--底部-->
<footer class="ui inverted vertical segment m-padded-t-massive">
    <div class="ui center aligned container">
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}"
                             class="ui rounded image" alt="" style="width: 110px">
                    </div>
                </div>
            </div>
            <div class="two wide column">
                <h4 class="ui inverted header">Skills</h4>
                <div class="skill-container">
                    <div class="ui two column stackable grid">
                        <div class="column">
                            <div class="ui inverted link list">
                                <a href="#" th:href="@{/detail-skill/1}" target="_blank" class="item">火灾</a>
                                <a href="#" th:href="@{/detail-skill/2}" class="item">地震</a>
                                <a href="#" th:href="@{/detail-skill/3}" class="item">暴风雨</a>
                            </div>
                        </div>
                        <div class="column">
                            <div class="ui inverted link list">
                                <a href="#" th:href="@{/detail-skill/4}" target="_blank" class="item">泥石流</a>
                                <a href="#" th:href="@{/detail-skill/5}" class="item">海啸</a>
                                <a href="#" th:href="@{/detail-skill/6}" class="item">雷震</a>
                            </div>
                        </div>

                    </div>

                </div>
            </div>
            <div class="four wide column">
                <h4 class="ui inverted header">Contact me</h4>
                <div class="ui divider"></div>
                <div class="ui inverted link list">
                    <a href="#" class="item">WeChat 18131605102</a>
                    <a href="#" class="item">Email 2194510807@qq.com</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header">Link</h4>
                <div class="ui small images">
                    <a href="https://www.mem.gov.cn/" class="ui image">
                        <img src="../static/images/guojia.png" th:src="@{/images/guojia.png}">
                    </a>
                    <a href="http://eeh.emerinfo.cn/dist/#/home" class="ui image">
                        <img src="../static/images/yingji.png" th:src="@{/images/yingji.png}">
                    </a>
                    <a href="http://120.39.net/" class="ui image">
                        <img src="../static/images/39.png" th:src="@{/images/39.png}">
                    </a>
                    <a href="https://www.beijing120.com/" class="ui image">
                        <img src="../static/images/beijing120.png" th:src="@{/images/beijing120.png}">
                    </a>
                    <a href="http://yjt.shandong.gov.cn/" class="ui image">
                        <img src="../static/images/shandong.png" th:src="@{/images/shandong.png}">
                    </a>
                    <a href="http://yjglj.beijing.gov.cn/" class="ui image">
                        <img src="../static/images/beijing.png" th:src="@{/images/beijing.png}">
                    </a>
                </div>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-spaced m-opacity-mini">Copyright &copy; 2022 Khan Designed by Liushun</p>
    </div>

</footer>

<script src="https://unpkg.com/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="https://unpkg.com/semantic-ui@2.4.2/dist/semantic.min.js"></script>

<script th:inline="javascript">

    $('#send-btn').click(function (){
       $('[name="Ereceiver"]').val([[${force.email}]]);
       $('#email-form').submit();
    });

    $('.menu.toggle').click(function(){
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $(function () {
        $("#comment-container").load(/*[[@{/comments/{id}(id=${force.id})}]]*/"comments/6");
    });

    //评论表单验证
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }
                ]
            },
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '请输入你的大名'
                }]
            },
            type: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });

    //校验
    $('#commentpost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        if (boo) {
            console.log('校验成功');
            postData();
        } else {
            console.log('校验失败');
        }

    });

    function postData() {
        $("#comment-container").load(/*[[@{/comments}]]*/"",{
            "force.id" : $("[name='force.id']").val(),
            "nickname": $("[name='nickname']").val(),
            "email"   : $("[name='email']").val(),
            "content" : $("[name='content']").val()
        },function (responseTxt, statusTxt, xhr) {
//        $(window).scrollTo($('#comment-container'),500);
            clearContent();
        });
    }

    function clearContent() {
        $("[name='content']").val('');
        $("[name='content']").attr("placeholder", "请输入评论信息...");
    }
</script>
</body>
</html>